<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改行政组')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-group-edit" th:object="${group}">
			<input id="groupId" name="groupId" type="hidden" th:field="*{groupId}"/>
			<input id="leaderTableId" name="leaderId" type="hidden" th:field="*{leaderId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">行政组名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupName" id="groupName" th:field="*{groupName}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">岗位编码：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupCode" id="groupCode" th:field="*{groupCode}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">组长：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input class="form-control" type="text" onclick="selectLeaderWindow()" id="leaderTableName" readonly="true" th:value="${group.leader == null ? '无' : group.leader.userName}">
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示顺序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupSort" id="groupSort" th:field="*{groupSort}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">行政组状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/group";
		
		$("#form-group-edit").validate({
			onkeyup: false,
			rules:{
				groupName:{
					remote: {
		                url: ctx + "system/group/checkGroupNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"groupId": function() {
							    return $("input[name='groupId']").val();
							},
		                	"groupName" : function() {
		                        return $.common.trim($("#groupName").val());
		                    }
		                }
		            }
				},
				groupCode:{
					remote: {
		                url: ctx + "system/group/checkGroupCodeUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"groupId": function() {
							    return $("input[name='groupId']").val();
							},
		                	"groupCode" : function() {
		                		return $.common.trim($("#groupCode").val());
		                    }
		                }
		            }
				},
				postSort:{
					digits:true
				},
			},
			messages: {
		        "groupCode": {
		            remote: "行政组编码已经存在"
		        },
		        "groupName": {
		            remote: "行政组名称已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-group-edit').serialize());
	        }
	    }
        /*行政组管理-新增-选择组长列表*/
        function selectLeaderWindow() {
          var treeId = $("#leaderTableId").val();
          var leaderId = treeId > 0 ? treeId : 1;
          var options = {
            title: '组长选择',
            width: "800",
            url: ctx + "system/user/selectUserList/"+leaderId,
            callBack: doSubmit
          };
          $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
          var body = $.modal.getChildFrame(index);
          $("#leaderTableId").val(body.find('#tableId').val());
          $("#leaderTableName").val(body.find('#tableName').val());
          $.modal.close(index);
        }
	</script>
</body>
</html>
